package com.mikepenz.app.activity.login;

import android.app.ProgressDialog;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.mikepenz.app.R;
import com.mikepenz.presenter.imp.RegistPresenterImp;
import com.mikepenz.view.RegiestView;
import com.quickdv.activity.BaseActivity;
import com.quickdv.until.AlertHelper;

import butterknife.InjectView;
import butterknife.OnClick;

public class RegistActivity extends BaseActivity implements RegiestView {

    @InjectView(R.id.regest_toast)
    TextView regestToast;
    @InjectView(R.id.regist_phone)
    EditText registPhone;
    @InjectView(R.id.regist_sms)
    Button registSms;
    @InjectView(R.id.regist_mark)
    EditText registMark;
    @InjectView(R.id.regist_pwd)
    EditText registPwd;
    @InjectView(R.id.regist_submit)
    Button registSubmit;
    ProgressDialog dialog;
    RegistPresenterImp presenter;
    @Override
    public int getLayoutID() {
        return R.layout.activity_regest;
    }

    @Override
    public void initView() {
        AlertHelper helper = new AlertHelper(this);
        dialog = helper.LoadingAlert();
    }

    @Override
    public void initActionbar() {

    }

    @Override
    public void initData() {
        presenter = new RegistPresenterImp(this);
    }

    @Override
    public void setPhoneError(String error) {
        registPhone.setError(error);
    }

    @Override
    public void setSmsError(String error) {
        registMark.setError(error);
    }

    @Override
    public void setPwdError(String error) {
        registPwd.setError(error);
    }

    @Override
    public void setPWd2Error(String error) {

    }

    @Override
    public String getPhone() {
        return registPhone.getText().toString();
    }

    @Override
    public String getPwd() {
        return registPwd.getText().toString();
    }

    @Override
    public String getSms() {
        return registMark.getText().toString();
    }

    @Override
    public void showLoad() {
        if (dialog!=null)
            dialog.show();
    }

    @Override
    public void dismissLoad() {
        if (dialog!=null)
            dialog.dismiss();
    }

    @Override
    public void showInfo(String str) {
        Toast.makeText(this,str,Toast.LENGTH_LONG).show();
    }

    @Override
    public void setButton(String str, Boolean clickable) {
        registSms.setClickable(clickable);
        registSms.setText(str);
    }

    @Override
    public void setButtonBackground(int color) {
        registSms.setBackgroundColor(getResources().getColor(color));
    }

    @OnClick({R.id.regist_sms,R.id.regist_submit})
    void onClick(View view){
        switch (view.getId()){
            case R.id.regist_sms:
                presenter.getSms();
                break;
            case R.id.regist_submit:
                presenter.Regist();
                break;
        }
    }

}
